package xin.workflow.rest;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.List;

/**
 * <pre>
 * Table Response
 * </pre>
 *
 * @author lixin_ma@outlook.com
 * @version 1.0
 * @since 2018/12/19
 */
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class TableResponse<T> extends BaseResponse {

    TableData<T> data;

    public TableResponse(long total, List<T> rows) {
        this.data = new TableData<T>(total, rows);
    }

    public TableResponse() {
        this.data = new TableData<T>();
    }

    TableResponse<T> total(int total) {
        this.data.setTotal(total);
        return this;
    }

    TableResponse<T> total(List<T> rows) {
        this.data.setRows(rows);
        return this;
    }

    class TableData<T> {
        long total;
        List<T> rows;

        public TableData(long total, List<T> rows) {
            this.total = total;
            this.rows = rows;
        }

        public TableData() {
        }

        public long getTotal() {
            return total;
        }

        public void setTotal(long total) {
            this.total = total;
        }

        public List<T> getRows() {
            return rows;
        }

        public void setRows(List<T> rows) {
            this.rows = rows;
        }
    }
}
